import 'package:auto_route/annotations.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:distribution_mall_flutter/http/modules/common.dart';
import 'package:distribution_mall_flutter/pages/agreement/presentation/domain/privacy_entity.dart';
import 'package:distribution_mall_flutter/utils/common_widget.dart';
import 'package:distribution_mall_flutter/widgets/loading.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

@RoutePage()
class PrivacyPage extends StatefulWidget {
  final String title, indexKey;

  const PrivacyPage(
      {super.key,
      @pathParam required this.title,
      @pathParam required this.indexKey});

  @override
  State<PrivacyPage> createState() => _PrivacyPageState();
}

class _PrivacyPageState extends State<PrivacyPage> {
  PrivacyBody? data;

  @override
  void initState() {
    super.initState();
    () async {
      (await CommonApi.commonQuestionT(
        widget.indexKey,
      ))
          .yes((value) {
        if (mounted) {
          data = value;
          setState(() {});
        }
      });
    }();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(S.current.legal_policies),
        centerTitle: true,
        leading: CommonBtnWidget.arrowBack(),
      ),
      body: data == null
          ? const Center(child: Loading())
          : SingleChildScrollView(
              padding: const EdgeInsets.symmetric(horizontal: 15),
              child: Html(
                data: data?.content ?? '',
              ),
            ),
    );
  }
}
